% SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0
\section{Wireless Debugging}\label{sec:wireless-debugging} %%##$section-title>>
%%!!intro<<
If you are running Android 11 or later and capable of connecting to a Wi-Fi network for, at least, a few moments,
Wireless Debugging is the recommended approach as it offers more protection than \hyperref[sec:adb-over-tcp]{ADB over TCP}.
It requires two steps:
\begin{enumerate}
    \item \textbf{ADB pairing.} The initial and a bit complex step for a novice user. Fortunately,
    this step is not required all the time.
    \item \textbf{Connecting to ADB.} Needs to be done every time you reboot your phone. App Manager
    can also automate this step in most devices.
\end{enumerate}
%%!!>>

\subsection{Enable developer options and USB Debugging}\label{subsec:enable-developer-options-and-usb-debugging} %%##$enable-developer-options-and-usb-debugging-title>>
%%!!enable-developer-options-and-usb-debugging<<
See \Sref{subsec:enable-developer-options} and \Sref{subsec:enable-usb-debugging}.
%%!!>>

\subsection{Enable Wireless Debugging}\label{subsec:enable-wireless-debugging} %%##$enable-wireless-debugging-title>>
%%!!enable-wireless-debugging<<
In the \textbf{Developer options} page, find \textbf{Wireless debugging} and click to open it. In
the new page, turn on \textit{Use wireless debugging}. Depending on the operating system, you might
see a dialog prompt asking you to verify your decision. If that is the case, click \textit{Allow}.

\begin{tip}{Tip}
    For easy access, you might want to add \textbf{Wireless debugging} in the notification tiles
    section. To do this, find \textbf{Quick settings developer tiles} in the \textbf{Developer
    options} page and click to open it. In the new window, enable \textit{Wireless debugging}.
    In case you do not see this setting, you may find a \textbf{Wireless debugging} tile in the tile
    customization panel.
\end{tip}
%%!!>>

\subsection{Pair ADB with App Manager}\label{subsec:pair-adb-with-app-manager} %%##$pair-adb-with-appmanager-title>>
%%!!pair-adb-with-app-manager<<
In App Manager, navigate to \textbf{Settings} > \hyperref[subsec:mode-of-operation]{Mode of operation}
and then enable \textit{Wireless debugging}. At this, App Manager will try to establish a wireless
debugging connection automatically which will fail if it has not been paired before. Once it fails,
it will ask you to either connect or pair ADB\@. Select \textit{pair} and a new dialog will appear.
It will ask you to navigate to the \textbf{Wireless debugging} page.

\begin{tip}{Note}
    As of v4.0.0, pairing is done using a notification prompt. So, if you have disabled notification
    for App Manager, you must enable it first.
\end{tip}

In the \textbf{Wireless debugging} page, select \textbf{Pair device with pairing code}. At this, a
dialog containing a pairing code will be displayed. A notification asking for the pairing code will
also be visible almost instantly. Insert the pairing code in the input box in the notification
and click \textit{pair}. If the pairing is successful, App Manager will display notification with
the message ``paired'', and the dialog in the \textbf{Wireless debugging} page will be dismissed
automatically. You will also be able to see App Manager listed as an ADB client in the same page.

\begin{tip}{Notice}
    If you do not use App Manager in ADB mode for a while, App Manager might be removed from the
    list of clients. In that case, you have to repeat the above procedure.
\end{tip}
%%!!>>

\subsection{Connect App Manager to ADB}\label{subsec:connect-app-manager-to-adb} %%##$connect-am-to-adb-title>>
%%!!connect-am-to-adb<<
App Manager should be able to connect to ADB automatically if the mode of operation is set to
\textit{auto}, \textit{ADB over TCP} or \textit{Wireless debugging}. If this is not the case, select
\textit{Wireless debugging} in \textbf{Settings} > \hyperref[subsec:mode-of-operation]{Mode of operation}.
If App Manager fails to detect or connect to ADB, it will ask you to connect or pair ADB. Select
\textit{connect}.

Now, navigate to the \textbf{Wireless debugging} page in Android settings, and note down the port
number displayed in the page. In App Manager's dialog prompt, replace the port number with the one
you have noted earlier, and click \textit{connect}.

Once a connection has been established, you can disable \textbf{Wireless debugging} in Android settings.

\begin{danger}{Caution}
    Never disable \textbf{USB Debugging} or any other additional options described in \Sref{subsec:enable-developer-options-and-usb-debugging}.
    If you do this, the remote server used by App Manager will be stopped, and you may have to start all over again.
\end{danger}
%%!!>>